<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *售后列表
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';

$tabs=array(
	array('op'=>'list','title'=>'案例'),
	array('op'=>'edit','title'=>'添加案例'),
);
$batch=array(
	//array('type'=>'post','url'=>'/member.list/setstore/','title'=>'一键归属门店'),
);
//列表
if($_RQ['op']=='list'){
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$return['params']=array();
	$params=array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']);
	if(!empty($_RQ['title'])){
		$params['title like']='%'.$_RQ['title'].'%';
		$return['params']['title']=$_RQ['title'];
	}
	if(!empty($_RQ['mobile'])){
		$params['mobile']=$_RQ['mobile'];
		$return['params']['mobile']=$_RQ['mobile'];
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = $_RQ['psize']?:10;
	$list=pdo_getslice('jy_yxw_anli',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	//页面显示设置
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'[温馨提示]：
		</br>1、这里显示本门店的案例！
		','del_message'=>'确认删除该案例吗？','total'=>$total,'psize'=>$psize,'del_op'=>'del','html_to'=>'list_html','list'=>array(
			array('type'=>'string','title'=>'案例名称','name'=>'title'),
			array('name'=>'sn','title'=>'案例编号','type'=>'string'),
			array('name'=>'kechengid','title'=>'绑定使用','type'=>'select','options'=>'kechengs'),
			array('name'=>'fee','title'=>'案例薪资','type'=>'string'),
			array('name'=>'status','title'=>'状态','type'=>'switch','set'=>'set'),
			array('name'=>'createtime','title'=>'日期','type'=>'time'),
		),'action'=>array(
			//array('type'=>'href_blank','name'=>'fileurl','title'=>'查看案例附件'),
		),'batch'=>$batch),
		'search'=>array(
			array('type'=>'string','width'=>'15','title'=>'案例名称','name'=>'title','help'=>''),
			array('name'=>'status','width'=>'15','title'=>'状态','type'=>'radio','options'=>'status'),
		),
	);
	$return['kechengs']=$this->getall('kecheng',array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');	
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='set'){
	$post=get_postdata();
	$id=intval($_RQ['id']);
	pdo_update('jy_yxw_anli',array('status'=>intval($post['status'])),array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	exi('操作成功！');
}
if($_RQ['op']=='edit'){
	$return=array();
	$id=intval($_RQ['id']);
	if($id){
		$item=pdo_get('jy_yxw_anli',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'tabs'=>array(
			array('op'=>'list','title'=>'返回案例列表'),
		),
		'edit'=>array(
			array('type'=>'string','title'=>'案例名称','name'=>'title'),
			array('name'=>'sn','title'=>'案例编号','type'=>'string'),
			array('type'=>'string','title'=>'案例描述','name'=>'desc'),
			array('type'=>'image','title'=>'案例图片','name'=>'image'),
			array('name'=>'kechengid','title'=>'绑定使用','type'=>'select','options'=>'kechengs'),
			array('name'=>'fee','title'=>'案例薪资','type'=>'string'),
			array('type'=>'richtext','title'=>'案例内容','name'=>'content'),
			array('name'=>'status','title'=>'状态','type'=>'switch','set'=>'set'),
		)
	);
	$return['kechengs']=$this->getall('kecheng',array('storeid'=>$_SESSION['storeid'],'uniacid'=>$_SESSION['uniacid']),array('id','title'),'id');
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	$data=array(
		'title'=>trim($postdata['title']),
		'sn'=>trim($postdata['sn']),
		'fee'=>trim($postdata['fee']),
		'content'=>trim($postdata['content']),
		'desc'=>trim($postdata['desc']),
		'image'=>trim($postdata['image']),
		'fee'=>intval($postdata['fee']),
		'kechengid'=>intval($postdata['kechengid']),
		'status'=>intval($postdata['status']),
	);
	$id=intval($postdata['id']);
	$mid=intval($postdata['mid']);
	if($id){
		pdo_update('jy_yxw_anli',$data,array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		$data['storeid']=$_SESSION['storeid'];
		$data['createtime']=TIMESTAMP;
		pdo_insert('jy_yxw_anli',$data);
	}
	exi('操作成功！','','goback');
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_yxw_anli',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}